#include "symbol.h"
#include "table.h"
#include <assert.h>

void test0() {
    sym_pool sp = cre_sym_pool();
    table tbl = cre_table();
    begin_scope(tbl);
    table_enter(tbl, sym_pool_get(sp, "a"), 1);
    table_enter(tbl, sym_pool_get(sp, "b"), 2);
    table_enter(tbl, sym_pool_get(sp, "c"), 3);
    begin_scope(tbl);
    table_enter(tbl, sym_pool_get(sp, "b"), 5);
    table_enter(tbl, sym_pool_get(sp, "c"), 6);
    table_enter(tbl, sym_pool_get(sp, "fe"), 12);

    assert(table_look(tbl, sym_pool_get(sp, "a")) == 1);
    assert(table_look(tbl, sym_pool_get(sp, "b")) == 5);
    assert(table_look(tbl, sym_pool_get(sp, "c")) == 6);
    end_scope(tbl);
    assert(table_look(tbl, sym_pool_get(sp, "a")) == 1);
    assert(table_look(tbl, sym_pool_get(sp, "b")) == 2);
    assert(table_look(tbl, sym_pool_get(sp, "fe")) == 0);
    end_scope(tbl);

    rel_sym_pool(sp);
    rel_table(tbl);
}

void test1() {
    sym_pool sp = cre_sym_pool();
    table tbl = cre_table();
    begin_scope(tbl);
    table_enter(tbl, sym_pool_get(sp, "a"), 1);
    table_enter(tbl, sym_pool_get(sp, "b"), 2);
    table_enter(tbl, sym_pool_get(sp, "c"), 3);
    assert(table_look(tbl, sym_pool_get(sp, "a")) == 1);
    end_scope(tbl);
    begin_scope(tbl);
    table_enter(tbl, sym_pool_get(sp, "b"), 5);
    table_enter(tbl, sym_pool_get(sp, "c"), 6);
    table_enter(tbl, sym_pool_get(sp, "fe"), 12);

    assert(table_look(tbl, sym_pool_get(sp, "a")) == 0);
    assert(table_look(tbl, sym_pool_get(sp, "b")) == 5);
    assert(table_look(tbl, sym_pool_get(sp, "c")) == 6);
    end_scope(tbl);
    assert(table_look(tbl, sym_pool_get(sp, "a")) == 0);
    assert(table_look(tbl, sym_pool_get(sp, "b")) == 0);
    assert(table_look(tbl, sym_pool_get(sp, "fe")) == 0);

    rel_sym_pool(sp);
    rel_table(tbl);
}

int main() {
    test0();
    test1();
}